# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  def page_title
    "北京空调团购集采网--"+(sanitize(@page_title) || controller.action_name)
  end
  def page_key
    sanitize(@page_key) || "北京 空调 团购 采集 集采"
  end
  def page_des
    sanitize(@page_title) || "北京空调团购集采,北京空调团购采集,集空调采购及空调相关资讯文章"
  end
  def display_advertisement(position,adddiv=false)
    return unless position
    ad=Advertisement.find_by_name(position.underscore)
    case ad.style.style_type
    when "image"      
      adv="<a href='#{ad.link}'><img align='center' src='/images/newsimgs/#{ad.image_name} ' #{"width="+ad.width.to_s+"px" if ad.width}  #{("height="+ad.height.to_s+"px") if ad.height}/></a>"
      adv=%{
          <div class='ad'>#{adv}</div>
      } if adddiv
      adv
    when "flash"
      %{
        <OBJECT codeBase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"
				height="476" width="1000" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" VIEWASTEXT>
				<PARAM NAME="FlashVars" VALUE="">
				<PARAM NAME="Movie" VALUE="/images/newsimgs/#{ad.image_name}">
				<PARAM NAME="Src" VALUE="/images/newsimgs/#{ad.image_name}">
				<PARAM NAME="WMode" VALUE="Window">
				<PARAM NAME="Play" VALUE="-1">
				<PARAM NAME="Loop" VALUE="-1">
				<PARAM NAME="Quality" VALUE="High">
				<PARAM NAME="SAlign" VALUE="">
				<PARAM NAME="Menu" VALUE="-1">
				<PARAM NAME="Base" VALUE="">
				<PARAM NAME="AllowScriptAccess" VALUE="">
				<PARAM NAME="Scale" VALUE="ShowAll">
				<PARAM NAME="DeviceFont" VALUE="0">
				<PARAM NAME="EmbedMovie" VALUE="0">
				<PARAM NAME="BGColor" VALUE="">
				<PARAM NAME="SWRemote" VALUE="">
				<PARAM NAME="MovieData" VALUE="">
				<PARAM NAME="SeamlessTabbing" VALUE="1">
				<PARAM NAME="Profile" VALUE="0">
				<PARAM NAME="ProfileAddress" VALUE="">
				<PARAM NAME="ProfilePort" VALUE="0">
				<embed src="/images/newsimgs/#{ad.image_name}" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer"
					type="application/x-shockwave-flash"> </embed>
			</OBJECT>
      }
    when "code" then ad.content
    else
      nil
    end
  end
  def get_cate_articles(o)
    o.articles.find(:all,:limit=>10,:order=>"created_at desc")
  end
  def get_configs(*styles)
    Webconfig.all(:conditions=>["style in (?)",styles.blank? ? 1 : styles])
  end
  def add_product_link(text,product,css_class=nil)
    link_to_remote text,{:url=>{:controller=>"cart",:action=>"add",:id=>product}},
      {:href=>url_for(:controller=>"cart",:action=>"add",:id=>product),:class=>css_class}
  end
  def remove_product_link(text,product,css_class=nil)
    link_to_remote text,{:url=>{:controller=>"cart",:action=>"remove",:id=>product}},
      {:href=>url_for(:controller=>"cart",:action=>"remove",:id=>product),:class=>css_class}
  end
  def clear_cart_link(text="清空购物车",css_class=nil)
    link_to_remote text,{:url=>{:controller=>"cart",:action=>"clear"}},
      {:href=>url_for(:controller=>"cart",:action=>"clear"),:class=>css_class}
  end

end
